/*     fb2 parsing library */
/*     Copyright (C) 2009 of Pavel Bibergal> */

/*     This program is free software: you can redistribute it and/or modify */
/*     it under the terms of the GNU General Public License as published by */
/*     the Free Software Foundation, either version 3 of the License, or */
/*     (at your option) any later version. */

/*     This program is distributed in the hope that it will be useful, */
/*     but WITHOUT ANY WARRANTY; without even the implied warranty of */
/*     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the */
/*     GNU General Public License for more details. */

/*     You should have received a copy of the GNU General Public License */
/*     along with this program.  If not, see <http://www.gnu.org/licenses/>. */


#include "fb2.h"
#include <stdlib.h>
#include <stdio.h>
#include <libxml/tree.h>
#include <libxml/parser.h>

fb2_context_t * fb2_create_context()
{
  return (fb2_context_t *) calloc(1, sizeof(fb2_context_t));
}


void fb2_destroy_context(fb2_context_t * context)
{
  free(context);
}

void print_node_names(xmlNode * node, int level)
{
    xmlNode *cur_node = NULL;

    for (cur_node = node; cur_node; cur_node = cur_node->next) {
      printf("node type: (%d) %d,  %s, name: %s\n", level, cur_node->type, cur_node->name, cur_node->content);
      print_node_names(cur_node->children, level + 1);

    }

}

fb2_context_t * fb2_parse_xml(xmlNode * rootNode)
{
  print_node_names(rootNode, 1);
}

fb2_context_t * fb2_parse_file(fb2_filename_t filename)
{
  LIBXML_TEST_VERSION

  xmlDoc * doc = xmlReadFile(filename, NULL, 0);

  xmlNode * rootNode = xmlDocGetRootElement(doc);
  fb2_parse_xml(rootNode);
  xmlFreeDoc(doc);
  xmlCleanupParser();
}
